package com.example.service;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.example.entity.AssetServerApplyItemVO;
import com.example.entity.AssetServerApplyVO;
import org.apache.poi.poifs.crypt.EncryptionInfo;
import org.apache.poi.poifs.crypt.EncryptionMode;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.security.GeneralSecurityException;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

/**
 * Author wangJinLong
 * Date 2025/11/21 09:59
 **/
@Service
public class AssetExcelService {

    private Integer rowCount = 0;
    private Integer columnWidth = 12 * 256;

    // 创建不同样式的 CellColor
    private byte[] serverColor = new byte[]{(byte) 112, (byte) 173, (byte) 71};
    private byte[] subTypeColor = new byte[]{(byte) 255, (byte) 192, (byte) 0};
    private byte[] headerColor = new byte[]{(byte) 214, (byte) 220, (byte) 228};
    private byte[] cellColor = new byte[]{(byte) 204, (byte) 232, (byte) 207};

    /**
     * 创建附件
     * @param filepath
     * @param filePassword
     * @throws GeneralSecurityException
     */
    public void createExcel(String filepath, String filePassword) {
        rowCount = 0;

        try (Workbook workbook = new XSSFWorkbook()) {
            Sheet serverSheet = workbook.createSheet("服务器申请信息");
            // 创建服务器excel
            createServerExcel(workbook, serverSheet);

            // 保存文件
            if (!StringUtils.hasLength(filePassword)) {
                // 不加密
                try (FileOutputStream fos = new FileOutputStream(filepath)) {
                    workbook.write(fos);
                }
            } else {
                // 加密
                try (POIFSFileSystem fs = new POIFSFileSystem()) {
                    // 创建EncryptionInfo对象，这里我们使用标准的加密模式
                    EncryptionInfo info = new EncryptionInfo(EncryptionMode.standard);

                    // 创建Encryptor实例
                    org.apache.poi.poifs.crypt.Encryptor enc = info.getEncryptor();
                    enc.confirmPassword(filePassword); // 设置打开文件的密码

                    // 写入内容到Encryptor的输出流中
                    try (OutputStream os = enc.getDataStream(fs)) {
                        workbook.write(os); // 将工作簿的内容写入到加密输出流中
                    }

                    // 最后将加密后的文件写入到磁盘
                    try (FileOutputStream fos = new FileOutputStream(filepath)) {
                        fs.writeFilesystem(fos); // 将整个加密的文件系统写入到文件输出流
                    }
                }
            }
        } catch (IOException | GeneralSecurityException e) {
            e.printStackTrace();
        }
    }

    private void createServerExcel(Workbook workbook, Sheet serverSheet) {
        Random random = new Random();

        // 申请新服务器
        List<AssetServerApplyVO> serverApplyData = getServerApplyData(random.nextInt(3) + 2);
        createServAppfor(workbook, serverSheet, serverApplyData);
        System.out.println("rowCount:" + rowCount);
        rowCount++;

        // 回收服务器或特权账号
        List<AssetServerApplyVO> serverRecoverData = getServerRecoverData(random.nextInt(3) + 1);
        createRecover(workbook, serverSheet, serverRecoverData);
        System.out.println("rowCount:" + rowCount);
        rowCount++;

        // 申请特权账号 privileged
        List<AssetServerApplyVO> serverPrivilegedData = getServerPrivilegedData(random.nextInt(3) + 1);
        createPrivileged(workbook, serverSheet, serverPrivilegedData);
        System.out.println("rowCount:" + rowCount);
        rowCount++;

        // 修改密码 editPw
        List<AssetServerApplyVO> serverEditPwData = getServerEditPwData(random.nextInt(3) + 1);
        createEditPw(workbook, serverSheet, serverEditPwData);
        System.out.println("rowCount:" + rowCount);
        rowCount++;

    }

    public void createServerExcel(String filepath, String filePassword) throws GeneralSecurityException {
        rowCount = 0;
        try (Workbook workbook = new XSSFWorkbook()) {
            Sheet serverSheet = workbook.createSheet("服务器");
            Random random = new Random();

            // 申请新服务器
            List<AssetServerApplyVO> serverApplyData = getServerApplyData(random.nextInt(3) + 2);
            createServAppfor(workbook, serverSheet, serverApplyData);
            System.out.println("rowCount:" + rowCount);
            rowCount++;

            // 回收服务器或特权账号
            List<AssetServerApplyVO> serverRecoverData = getServerRecoverData(random.nextInt(3) + 1);
            createRecover(workbook, serverSheet, serverRecoverData);
            System.out.println("rowCount:" + rowCount);
            rowCount++;

            // 申请特权账号 privileged
            List<AssetServerApplyVO> serverPrivilegedData = getServerPrivilegedData(random.nextInt(3) + 1);
            createPrivileged(workbook, serverSheet, serverPrivilegedData);
            System.out.println("rowCount:" + rowCount);
            rowCount++;

            // 修改密码 editPw
            List<AssetServerApplyVO> serverEditPwData = getServerEditPwData(random.nextInt(3) + 1);
            createEditPw(workbook, serverSheet, serverEditPwData);
            System.out.println("rowCount:" + rowCount);
            rowCount++;

            if (!StringUtils.hasLength(filePassword)) {
                // 不加密
                try (FileOutputStream fos = new FileOutputStream(filepath)) {
                    workbook.write(fos);
                }
            } else {
                // 加密
                try (POIFSFileSystem fs = new POIFSFileSystem()) {
                    // 创建EncryptionInfo对象，这里我们使用标准的加密模式
                    EncryptionInfo info = new EncryptionInfo(EncryptionMode.standard);

                    // 创建Encryptor实例
                    org.apache.poi.poifs.crypt.Encryptor enc = info.getEncryptor();
                    enc.confirmPassword(filePassword); // 设置打开文件的密码

                    // 写入内容到Encryptor的输出流中
                    try (OutputStream os = enc.getDataStream(fs)) {
                        workbook.write(os); // 将工作簿的内容写入到加密输出流中
                    }

                    // 最后将加密后的文件写入到磁盘
                    try (FileOutputStream fos = new FileOutputStream(filepath)) {
                        fs.writeFilesystem(fos); // 将整个加密的文件系统写入到文件输出流
                    }
                }
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 修改密码
     * @param workbook
     * @param sheet
     * @param editPwData
     */
    private void createEditPw(Workbook workbook, Sheet sheet, List<AssetServerApplyVO> editPwData) {
        // 创建不同样式的 CellStyle
        CellStyle serverStyle = createCellBackground(workbook.createCellStyle(), serverColor);
        CellStyle subTypeStyle = createCellBackground(workbook.createCellStyle(), subTypeColor);
        CellStyle headerStyle = createCellBackground(workbook.createCellStyle(), headerColor);
        CellStyle cellStyle = createCellBackground(workbook.createCellStyle(), cellColor);

        Row headerRow = sheet.createRow(rowCount++);
        headerRow.createCell(0).setCellValue("服务器");
        headerRow.createCell(1).setCellValue("密码修改");
        headerRow.getCell(0).setCellStyle(serverStyle);
        headerRow.getCell(1).setCellStyle(subTypeStyle);

        List<String> headerList = Arrays.asList(
                "使用场景", "资源评估依据", "数据中心", "服务器IP", "是否特权账号", "账号", "备注", "是否配置完成", "密码", "配置说明"
        );
        Row sheetRow = sheet.createRow(rowCount++);
        for (int i = 0; i < headerList.size(); i++) {
            Cell cell = sheetRow.createCell(i);
            cell.setCellValue(headerList.get(i));
            cell.setCellStyle(headerStyle);
        }

        for (AssetServerApplyVO applyVO : editPwData) {
            Row dataRow = sheet.createRow(rowCount++);
            for (int i = 0; i < headerList.size(); i++) {
                dataRow.createCell(i).setCellStyle(cellStyle);
            }

            dataRow.getCell(0).setCellValue(applyVO.getUsageScenario());
            dataRow.getCell(1).setCellValue(applyVO.getResourceAssessment());
            dataRow.getCell(2).setCellValue(applyVO.getDataCenter());
            dataRow.getCell(3).setCellValue(applyVO.getIp());
            dataRow.getCell(4).setCellValue("true".equals(applyVO.getIsNeedSpecialAccount()) ? "是" : "否");
            dataRow.getCell(5).setCellValue(applyVO.getAccount());
            dataRow.getCell(6).setCellValue(applyVO.getRemark());
            dataRow.getCell(7).setCellValue("true".equals(applyVO.getIsCompleted()) ? "是" : "否");
            dataRow.getCell(8).setCellValue(applyVO.getPassword());
            dataRow.getCell(9).setCellValue(applyVO.getConfigDesc());
        }

        // 设置列宽
        for (int i = 0; i < headerList.size(); i++) {
            if (sheet.getColumnWidth(i) < columnWidth) {
                sheet.setColumnWidth(i, columnWidth);
            }
        }

        rowCount++;
    }

    /**
     * 申请特权账号
     * @param workbook
     * @param sheet
     * @param serverPrivilegedData
     */
    private void createPrivileged(Workbook workbook, Sheet sheet, List<AssetServerApplyVO> serverPrivilegedData) {
        // 创建不同样式的 CellStyle
        CellStyle serverStyle = createCellBackground(workbook.createCellStyle(), serverColor);
        CellStyle subTypeStyle = createCellBackground(workbook.createCellStyle(), subTypeColor);
        CellStyle headerStyle = createCellBackground(workbook.createCellStyle(), headerColor);
        CellStyle cellStyle = createCellBackground(workbook.createCellStyle(), cellColor);

        Row headerRow = sheet.createRow(rowCount++);
        headerRow.createCell(0).setCellValue("服务器");
        headerRow.createCell(1).setCellValue("申请特权账号");
        headerRow.getCell(0).setCellStyle(serverStyle);
        headerRow.getCell(1).setCellStyle(subTypeStyle);

        List<String> headerList = Arrays.asList(
                "使用场景", "资源评估依据", "数据中心", "服务器IP", "特权账号类型", "权限使用开始时间", "权限使用结束时间",
                "备注", "是否配置完成", "特权账号", "特权账号密码", "配置说明"
        );
        Row sheetRow = sheet.createRow(rowCount++);
        for (int i = 0; i < headerList.size(); i++) {
            Cell cell = sheetRow.createCell(i);
            cell.setCellValue(headerList.get(i));
            cell.setCellStyle(headerStyle);
        }

        for (AssetServerApplyVO applyVO : serverPrivilegedData) {
            Row dataRow = sheet.createRow(rowCount++);
            for (int i = 0; i < headerList.size(); i++) {
                dataRow.createCell(i).setCellStyle(cellStyle);
            }

            dataRow.getCell(0).setCellValue(applyVO.getUsageScenario());
            dataRow.getCell(1).setCellValue(applyVO.getResourceAssessment());
            dataRow.getCell(2).setCellValue(applyVO.getDataCenter());
            dataRow.getCell(3).setCellValue(applyVO.getIp());
            dataRow.getCell(4).setCellValue(applyVO.getSpecialAccountType());
            dataRow.getCell(5).setCellValue(LocalDateTimeUtil.format(applyVO.getStartTime(), "yyyy-MM-dd HH:mm:ss"));
            dataRow.getCell(6).setCellValue(LocalDateTimeUtil.format(applyVO.getEndTime(), "yyyy-MM-dd HH:mm:ss"));
            dataRow.getCell(7).setCellValue(applyVO.getRemark());
            dataRow.getCell(8).setCellValue("true".equals(applyVO.getIsCompleted()) ? "是" : "否");
            dataRow.getCell(9).setCellValue(applyVO.getSpecialAccount());
            dataRow.getCell(10).setCellValue(applyVO.getSpecialPassword());
            dataRow.getCell(11).setCellValue(applyVO.getConfigDesc());
        }

        // 设置列宽
        for (int i = 0; i < headerList.size(); i++) {
            if (sheet.getColumnWidth(i) < columnWidth) {
                sheet.setColumnWidth(i, columnWidth);
            }
        }

        rowCount++;
    }

    /**
     * 回收服务器或者特权账号
     * @param workbook
     * @param sheet
     */
    private void createRecover(Workbook workbook, Sheet sheet, List<AssetServerApplyVO> serverRecoverData) {
        // 创建不同样式的 CellStyle
        CellStyle serverStyle = createCellBackground(workbook.createCellStyle(), serverColor);
        CellStyle subTypeStyle = createCellBackground(workbook.createCellStyle(), subTypeColor);
        CellStyle headerStyle = createCellBackground(workbook.createCellStyle(), headerColor);
        CellStyle cellStyle = createCellBackground(workbook.createCellStyle(), cellColor);

        Row headerRow = sheet.createRow(rowCount++);
        headerRow.createCell(0).setCellValue("服务器");
        headerRow.createCell(1).setCellValue("回收服务器或特权账号");
        headerRow.getCell(0).setCellStyle(serverStyle);
        headerRow.getCell(1).setCellStyle(subTypeStyle);

        List<String> headerList = Arrays.asList("使用场景", "资源评估依据", "数据中心", "服务器IP", "是否特权账号", "账号", "备注", "是否配置完成", "配置说明");
        Row sheetRow = sheet.createRow(rowCount++);
        for (int i = 0; i < headerList.size(); i++) {
            Cell cell = sheetRow.createCell(i);
            cell.setCellValue(headerList.get(i));
            cell.setCellStyle(headerStyle);
        }

        for (AssetServerApplyVO applyVO : serverRecoverData) {
            Row dataRow = sheet.createRow(rowCount++);
            for (int i = 0; i < headerList.size(); i++) {
                dataRow.createCell(i).setCellStyle(cellStyle);
            }

            // "使用场景", "资源评估依据", "数据中心", "服务器IP", "是否特权账号", "账号", "备注", "是否配置完成", "配置说明"
            dataRow.getCell(0).setCellValue(applyVO.getUsageScenario());
            dataRow.getCell(1).setCellValue(applyVO.getResourceAssessment());
            dataRow.getCell(2).setCellValue(applyVO.getDataCenter());
            dataRow.getCell(3).setCellValue(applyVO.getIp());
            dataRow.getCell(4).setCellValue("true".equals(applyVO.getIsNeedSpecialAccount()) ? "是" : "否");
            dataRow.getCell(5).setCellValue(applyVO.getAccount());
            dataRow.getCell(6).setCellValue(applyVO.getRemark());
            dataRow.getCell(7).setCellValue("true".equals(applyVO.getIsCompleted()) ? "true" : "false");
            dataRow.getCell(8).setCellValue(applyVO.getConfigDesc());
        }

        // 设置列宽
        for (int i = 0; i < headerList.size(); i++) {
            if (sheet.getColumnWidth(i) < columnWidth) {
                sheet.setColumnWidth(i, columnWidth);
            }
        }

        rowCount++;
    }

    /**
     * 申请新服务器
     * @param workbook
     * @param sheet
     */
    public void createServAppfor(Workbook workbook, Sheet sheet, List<AssetServerApplyVO> serverApplyData) {
        // 创建不同样式的 CellStyle
        CellStyle serverStyle = createCellBackground(workbook.createCellStyle(), serverColor);
        CellStyle subTypeStyle = createCellBackground(workbook.createCellStyle(), subTypeColor);
        CellStyle headerStyle = createCellBackground(workbook.createCellStyle(), headerColor);
        CellStyle cellStyle = createCellBackground(workbook.createCellStyle(), cellColor);

        List<String> headerList = Arrays.asList(
                "使用场景", "资源评估依据", "数据中心", "台数", "是否需特权账号", "特权账号类型", "权限使用开始时间", "权限使用结束时间",
                "备注", "是否配置完成"
        );
        List<String> itemHeaderList = Arrays.asList("服务器IP", "端口", "账号", "密码", "特权账号", "特权账号密码", "配置说明");

        List<String> allHeader = Arrays.asList(
                "使用场景", "资源评估依据", "数据中心", "台数", "是否需特权账号", "特权账号类型", "权限使用开始时间", "权限使用结束时间",
                "备注", "是否配置完成", "服务器IP", "端口", "账号", "密码", "特权账号", "特权账号密码", "配置说明"
        );

        Row headerRow = sheet.createRow(rowCount++);
        headerRow.createCell(0).setCellValue("服务器");
        headerRow.createCell(1).setCellValue("申请新服务器");
        headerRow.getCell(0).setCellStyle(serverStyle);
        headerRow.getCell(1).setCellStyle(subTypeStyle);

        Row subHeaderRow = sheet.createRow(rowCount++);
        for (int i = 0; i < allHeader.size(); i++) {
            Cell cell = subHeaderRow.createCell(i);
            cell.setCellValue(allHeader.get(i));
            cell.setCellStyle(headerStyle);
        }

        int firstRow = rowCount;
        for (AssetServerApplyVO applyVO : serverApplyData) {
            List<AssetServerApplyItemVO> applyItemVOS = applyVO.getServerApplyItemVOS();
            if (CollectionUtils.isEmpty(applyItemVOS)) {
                Row dataRow = sheet.createRow(rowCount++);
                int headerSize = headerList.size();
                for (int i1 = 0; i1 < headerSize; i1++) {
                    dataRow.createCell(i1).setCellStyle(cellStyle);
                }
                dataRow.getCell(0).setCellValue(applyVO.getUsageScenario());
                dataRow.getCell(1).setCellValue(applyVO.getResourceAssessment());
                dataRow.getCell(2).setCellValue(applyVO.getDataCenter());
                dataRow.getCell(3).setCellValue(applyVO.getAmount());
                dataRow.getCell(4).setCellValue("true".equals(applyVO.getIsNeedSpecialAccount()) ? "是" : "否");
                dataRow.getCell(5).setCellValue(applyVO.getSpecialAccountType());
                dataRow.getCell(6).setCellValue(LocalDateTimeUtil.format(applyVO.getStartTime(), "yyyy-MM-dd HH:mm:ss"));
                dataRow.getCell(7).setCellValue(LocalDateTimeUtil.format(applyVO.getEndTime(), "yyyy-MM-dd HH:mm:ss"));
                dataRow.getCell(8).setCellValue(applyVO.getRemark());
                dataRow.getCell(9).setCellValue("true".equals(applyVO.getIsCompleted()) ? "是" : "否");
            } else {
                for (AssetServerApplyItemVO applyItemVO : applyItemVOS) {
                    Row dataRow = sheet.createRow(rowCount++);
                    int headerSize = headerList.size();
                    for (int i1 = 0; i1 < headerSize; i1++) {
                        dataRow.createCell(i1).setCellStyle(cellStyle);
                    }
                    dataRow.getCell(0).setCellValue(applyVO.getUsageScenario());
                    dataRow.getCell(1).setCellValue(applyVO.getResourceAssessment());
                    dataRow.getCell(2).setCellValue(applyVO.getDataCenter());
                    dataRow.getCell(3).setCellValue(applyVO.getAmount());
                    dataRow.getCell(4).setCellValue("true".equals(applyVO.getIsNeedSpecialAccount()) ? "是" : "否");
                    dataRow.getCell(5).setCellValue(applyVO.getSpecialAccountType());
                    dataRow.getCell(6).setCellValue(LocalDateTimeUtil.format(applyVO.getStartTime(), "yyyy-MM-dd HH:mm:ss"));
                    dataRow.getCell(7).setCellValue(LocalDateTimeUtil.format(applyVO.getEndTime(), "yyyy-MM-dd HH:mm:ss"));
                    dataRow.getCell(8).setCellValue(applyVO.getRemark());
                    dataRow.getCell(9).setCellValue("true".equals(applyVO.getIsCompleted()) ? "是" : "否");

                    // "服务器IP", "端口", "账号", "密码", "特权账号", "特权账号密码", "配置说明"
                    for (int k = headerSize; k < itemHeaderList.size() + headerSize; k++) {
                        dataRow.createCell(k).setCellStyle(cellStyle);
                    }
                    for (int k = headerSize; k < itemHeaderList.size() + headerSize; k++) {
                        dataRow.getCell(10).setCellValue(applyItemVO.getIp());
                        dataRow.getCell(11).setCellValue(applyItemVO.getPort());
                        dataRow.getCell(12).setCellValue(applyItemVO.getAccount());
                        dataRow.getCell(13).setCellValue(applyItemVO.getPassword());
                        dataRow.getCell(14).setCellValue(applyItemVO.getSpecialAccount());
                        dataRow.getCell(15).setCellValue(applyItemVO.getSpecialPassword());
                        dataRow.getCell(16).setCellValue(applyItemVO.getConfigDesc());
                    }
                }

                // ==================== 合并单元格 ====================
                if (applyItemVOS.size() > 1) {
                    int lastRow = firstRow + applyItemVOS.size() - 1;
                    sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, 0, 0));
                    sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, 1, 1));
                    sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, 2, 2));
                    sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, 3, 3));
                    sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, 4, 4));
                    sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, 5, 5));
                    sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, 6, 6));
                    sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, 7, 7));
                    sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, 8, 8));
                    sheet.addMergedRegion(new CellRangeAddress(firstRow, lastRow, 9, 9));

                    firstRow = lastRow + 1;
                } else {
                    firstRow = firstRow + 1;
                }
            }
        }

        // 设置列宽
        for (int i = 0; i < allHeader.size(); i++) {
            if (sheet.getColumnWidth(i) < columnWidth) {
                sheet.setColumnWidth(i, columnWidth);
            }
        }
        rowCount++;
    }

    /**
     * 设置单元格样式
     * @param style
     * @param rgb
     * @return
     */
    private CellStyle createCellBackground(CellStyle style, byte[] rgb) {
        // 设置自定义颜色，使用RGB值
        XSSFColor color = new XSSFColor(rgb, null);
        style.setFillForegroundColor(color);
        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);

        // 居中
        style.setAlignment(HorizontalAlignment.CENTER);   // 水平居中
        style.setVerticalAlignment(VerticalAlignment.CENTER); // 垂直居中

        // 设置单元格的所有四边框样式
        style.setBorderTop(BorderStyle.THIN);
        style.setTopBorderColor(IndexedColors.BLACK1.getIndex());
        style.setBorderBottom(BorderStyle.THIN);
        style.setBottomBorderColor(IndexedColors.BLACK1.getIndex());
        style.setBorderLeft(BorderStyle.THIN);
        style.setLeftBorderColor(IndexedColors.BLACK1.getIndex());
        style.setBorderRight(BorderStyle.THIN);
        style.setRightBorderColor(IndexedColors.BLACK1.getIndex());

        return style;
    }

    private List<AssetServerApplyVO> getServerApplyData(int size) {
        List<AssetServerApplyVO> assetServerApplyVOS = new ArrayList<>();
        Random random = new Random();
        for (int i = 0; i < size; i++) {
            int nextInt = random.nextInt(size) + 1;
            AssetServerApplyVO applyVO = new AssetServerApplyVO();
            applyVO.setUsageScenario("回收服务器或特权账号");
            applyVO.setResourceAssessment("可以");
            applyVO.setDataCenter("呼和");
            applyVO.setAmount(nextInt);
            applyVO.setIsNeedSpecialAccount((size % nextInt) == 2 ? "true" : "false");
            applyVO.setSpecialAccountType("sudo");
            applyVO.setStartTime(LocalDateTime.now());
            applyVO.setEndTime(LocalDateTime.now().plusDays(1));
            applyVO.setRemark("配置完成");
            applyVO.setIsCompleted((size % nextInt) == 1 ? "true" : "false");

            List<AssetServerApplyItemVO> serverApplyItemData = getServerApplyItemData(nextInt);
            applyVO.setServerApplyItemVOS(serverApplyItemData);

            assetServerApplyVOS.add(applyVO);
        }
        return assetServerApplyVOS;
    }

    private List<AssetServerApplyItemVO> getServerApplyItemData(int size) {
        List<AssetServerApplyItemVO> applyItemVOS = new ArrayList<>();
        for (int i = 0; i < size; i++) {
            AssetServerApplyItemVO applyItemVO = new AssetServerApplyItemVO();
            applyItemVO.setId("199066264075640832" + i);
            applyItemVO.setIp("127.0.0." + i);
            applyItemVO.setPort(22);
            applyItemVO.setAccount("user" + i);
            applyItemVO.setPassword("123" + i);
            applyItemVO.setSpecialAccount("server" + i);
            applyItemVO.setSpecialPassword("server" + i);
            applyItemVO.setConfigDesc("配置完成");
            applyItemVOS.add(applyItemVO);
        }
        return applyItemVOS;
    }

    private List<AssetServerApplyVO> getServerRecoverData(int size) {
        List<AssetServerApplyVO> assetServerApplyVOS = new ArrayList<>();
        Random random = new Random();
        for (int i = 0; i < size; i++) {
            int nextInt = random.nextInt(size) + 1;
            AssetServerApplyVO applyVO = new AssetServerApplyVO();
            applyVO.setUsageScenario("回收服务器或特权账号");
            applyVO.setResourceAssessment("可以");
            applyVO.setDataCenter("呼和");
            applyVO.setIp("127.0.0." + i);
            applyVO.setIsNeedSpecialAccount((size % nextInt) == 2 ? "true" : "false");
            applyVO.setAccount("user" + i);
            applyVO.setRemark("备注1");
            applyVO.setIsCompleted((size % nextInt) == 1 ? "true" : "false");
            applyVO.setConfigDesc((size % nextInt) == 1 ? "配置完成" : "");

            assetServerApplyVOS.add(applyVO);
        }
        return assetServerApplyVOS;
    }

    private List<AssetServerApplyVO> getServerPrivilegedData(int size) {
        List<AssetServerApplyVO> assetServerApplyVOS = new ArrayList<>();
        Random random = new Random();
        for (int i = 0; i < size; i++) {
            int nextInt = random.nextInt(size) + 1;
            AssetServerApplyVO applyVO = new AssetServerApplyVO();
            applyVO.setUsageScenario("回收服务器或特权账号");
            applyVO.setResourceAssessment("可以");
            applyVO.setDataCenter("呼和");
            applyVO.setIp("127.0.0." + i);
            applyVO.setSpecialAccountType((size % nextInt) == 1 ? "免密sudo" : "sudo");
            applyVO.setStartTime(LocalDateTime.now());
            applyVO.setEndTime(LocalDateTime.now().plusDays(1));
            applyVO.setRemark("备注1");
            applyVO.setIsCompleted((size % nextInt) == 1 ? "true" : "false");
            applyVO.setSpecialAccount("user" + i);
            applyVO.setSpecialPassword("123" + i);
            applyVO.setConfigDesc((size % nextInt) == 1 ? "配置完成" : "");

            assetServerApplyVOS.add(applyVO);
        }
        return assetServerApplyVOS;
    }

    private List<AssetServerApplyVO> getServerEditPwData(int size) {
        List<AssetServerApplyVO> assetServerApplyVOS = new ArrayList<>();
        Random random = new Random();
        for (int i = 0; i < size; i++) {
            int nextInt = random.nextInt(size) + 1;
            AssetServerApplyVO applyVO = new AssetServerApplyVO();
            applyVO.setUsageScenario("回收服务器或特权账号");
            applyVO.setResourceAssessment("可以");
            applyVO.setDataCenter("呼和");
            applyVO.setIp("127.0.0." + i);
            applyVO.setIsNeedSpecialAccount((size % nextInt) == 1 ? "true" : "false");
            applyVO.setAccount("user" + i);
            applyVO.setRemark("备注1");
            applyVO.setIsCompleted((size % nextInt) == 1 ? "true" : "false");
            applyVO.setPassword("123" + i);
            applyVO.setConfigDesc((size % nextInt) == 1 ? "配置完成" : "");

            assetServerApplyVOS.add(applyVO);
        }
        return assetServerApplyVOS;
    }


}
